"""
satllite position file function write the position file
"""

import time


def outSatPosFile(satPos):

    start=time.time()
    PRN=satPos.iloc[0]['PRN']
    f = open('data\satPos_'+PRN+'.txt','w')

    header="{0:20s}     {1:5s}       {2:15s}        {3:15s}       {4:15s}        {5:20s}{6:20s}{7:20s}".format('Epoch','Prn','X(m)','Y(m)','Z(m)','Latitude(deg)','Longitude(deg)','Height(m)')
    f.write(header)
    f.write('\n')

    for i in range(len(satPos)):

        epoch=satPos.iloc[i]['epoch']
        epoch_str=epoch.strftime('%Y-%m-%d %H:%M:%S')
        
        line="{0:20s}     {1:5s}     ".format(epoch_str,PRN)
        line_="{0:15.7f}      {1:15.7f}     {2:15.7f}     ".format(satPos.iloc[i]['X'], satPos.iloc[i]['Y'], satPos.iloc[i]['Z'])
        line__="{0:15.7f}      {1:15.7f}     {2:15.7f}".format(satPos.iloc[i]['B'], satPos.iloc[i]['L'], satPos.iloc[i]['H'])
        f.write(line)
        f.write(line_)
        f.write(line__)
        f.write('\n')

    f.close()
    finish=time.time()
    print("Writing satellite position of ", PRN," is cost in", "{0:.2f}".format(finish-start), "seconds.")